package com.lucky.common.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ICaptcha;
import com.lucky.common.base.BaseController;
import com.lucky.common.cache.ParamCache;
import com.lucky.common.service.ParamService;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;


@Controller
public class IndexController extends BaseController {
	
	@Resource
	ParamService paramService;
	
	@RequestMapping("/index")
	public ModelAndView index(ModelMap model) {

		return new ModelAndView("/index");
	}


	@RequestMapping("/")
	public ModelAndView index0(ModelMap model) {

		return new ModelAndView("/index");
	}

	/**
	 * 生成验证码图片
	 */
	@GetMapping(value = "/captcha")
	public void captcha(HttpSession session, HttpServletResponse response) throws Exception {
//		CircleCaptcha//圆圈干扰ShearCaptcha//扭曲干扰LineCaptcha //线条干扰
		ICaptcha captcha = CaptchaUtil.createLineCaptcha(80, 30, 4, 1);
		response.setContentType("image/jpeg");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		try {
			String vcode = captcha.getCode();
			vcode = "1111";
			session.setAttribute("vcode", vcode);
			captcha.write(response.getOutputStream());
			response.getOutputStream().close();
		} catch (IOException e) {

			throw new RuntimeException(e);

		}
	}
}
